package com.example.myspringbootpj.service;

import com.example.myspringbootpj.entity.User;
import com.example.myspringbootpj.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
public class UserService {


    private final UserMapper userMapper;
    @Autowired
    public UserService(UserMapper userMapper) {
        this.userMapper = userMapper;
    }

    //是否封号
    public boolean IsBan(String user_id,String user_password){
        User user = userMapper.findBan(user_id,user_password);

        // 如果未找到用户，默认认为被封号
        if (user == null) {
            return true;
        }

        LocalDateTime user_not_use = user.getUser_not_use();

        // 如果 user_not_use 为 null，表示用户未被封号
        if (user_not_use == null) {
            return false;
        }

        LocalDateTime now = LocalDateTime.now();
        System.out.println("user_not_use: " + user_not_use + ", now: " + now);

        // 判断是否当前时间晚于封号时间
        return user_not_use.isAfter(now);


//            if(user == null){
//                return true;
//            }
//            LocalDateTime user_not_use = user.getUser_not_use();
//
//            //打印时间
//            LocalDateTime now = LocalDateTime.now();
//            System.out.println("user_not_use: " + user_not_use + ", now: " + now);
//
//            return user_not_use == null || user_not_use.isAfter(LocalDateTime.now());
        }

    //管理员封号
    public void BanUser(String user_id,LocalDateTime user_not_use){
        userMapper.setUserBan(user_id,user_not_use.toLocalDate());
    }
//查找用户
    public List<User> findAll(String user_id){
        return userMapper.selectUserList(user_id);
    }
}
